home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / POVSRC / SOURCE / FileQueue.c < prev    next >
Text File  |  1994-02-04  |  6KB  |  197 lines

  1. /*
  2. ==============================================================================
  3. Project:    POV-Ray
  4.  
  5. Version:    2.2
  6.  
  7. File Name:    FileQueue.c
  8.  
  9. Description:
  10.     Generic Macintosh File Spec queueing routine.  This is intended to
  11.     be used to collect the list of files passed in via System 7 ODOC
  12.     AppleEvents, for processing at a more convenient time.
  13.  
  14.     This is the main implementation of the functions.
  15.  
  16. Related Files:
  17.     FileQueue.h    - External interface for these routines
  18. ------------------------------------------------------------------------------
  19. Author:
  20.     Eduard [esp] Schwan
  21. ------------------------------------------------------------------------------
  22.     from Persistence of Vision Raytracer
  23.     Copyright 1993 Persistence of Vision Team
  24. ------------------------------------------------------------------------------
  25.     NOTICE: This source code file is provided so that users may experiment
  26.     with enhancements to POV-Ray and to port the software to platforms other 
  27.     than those supported by the POV-Ray Team.  There are strict rules under
  28.     which you are permitted to use this file.  The rules are in the file
  29.     named POVLEGAL.DOC which should be distributed with this file. If 
  30.     POVLEGAL.DOC is not available or for more info please contact the POV-Ray
  31.     Team Coordinator by leaving a message in CompuServe's Graphics Developer's
  32.     Forum.  The latest version of POV-Ray may be found there as well.
  33.  
  34.     This program is based on the popular DKB raytracer version 2.12.
  35.     DKBTrace was originally written by David K. Buck.
  36.     DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
  37. ------------------------------------------------------------------------------
  38. More Info:
  39.     This Macintosh version of POV-Ray was created and compiled by Jim Nitchals
  40.     (Think 5.0) and Eduard Schwan (MPW 3.2), based (loosely) on the original
  41.     port by Thomas Okken and David Lichtman, with some help from Glenn Sugden.
  42.  
  43.     For bug reports regarding the Macintosh version, you should contact:
  44.     Eduard [esp] Schwan
  45.         CompuServe: 71513,2161
  46.         Internet: jl.tech@applelink.apple.com
  47.         AppleLink: jl.tech
  48.     Jim Nitchals
  49.         Compuserve: 73117,3020
  50.         America Online: JIMN8
  51.         Internet: jimn8@aol.com -or- jimn8@applelink.apple.com
  52.         AppleLink: JIMN8
  53. ------------------------------------------------------------------------------
  54. Change History:
  55.     920820    [esp]    Created
  56.     921221    [esp]    Added logic in Get() routine to call destructor after getting last item
  57.     931001    [esp]    version 2.0 finished (Released on 10/4/93)
  58. ==============================================================================
  59. */
  60.  
  61. #include "FileQueue.h"
  62.  
  63. #include <memory.h>    // NewHandle
  64.  
  65.  
  66. // Class definition of internal File Queue object
  67. typedef struct
  68. {
  69.     flisthdl_t    fFlist;
  70.     flisthdl_t    fFlistEnd;
  71.     flisthdl_t    fFlistGetter;
  72.     short        fFlistNumItems;
  73. } ClassFileQueueRec_t, *ClassFileQueuePtr_t, **ClassFileQueueHdl_t;
  74.  
  75.  
  76. // a static global instance for our internal use
  77. ClassFileQueueRec_t    gFileQueue;
  78.  
  79.  
  80. // ------------------------------------------------------------------
  81. // Initialize the list handling structures prior to use
  82. void FileQ_c(void)
  83. {
  84.     gFileQueue.fFlist = NULL;
  85.     gFileQueue.fFlistEnd = NULL;
  86.     gFileQueue.fFlistGetter = NULL;
  87.     gFileQueue.fFlistNumItems = 0;
  88. } // FileQ_c
  89.  
  90.  
  91.  
  92. // ------------------------------------------------------------------
  93. // Add a file to the list
  94. void FileQ_Put(FSSpecPtr    pFSSpecPtr)
  95. {
  96.     flisthdl_t    newFlistHdl;
  97.  
  98.     // create new record
  99.     newFlistHdl = (flisthdl_t)NewHandle(sizeof(flistrec_t));
  100.  
  101.     if (newFlistHdl)
  102.     {
  103.         // fill it up
  104.         (**newFlistHdl).fFSSpec = *pFSSpecPtr;
  105.         (**newFlistHdl).fNext = NULL;
  106.     
  107. #if defined (DO_DEBUG)
  108. printf("PutFileInList - '%P'\n",(**newFlistHdl).fFSSpec.name);
  109. #endif // DO_DEBUG
  110.  
  111.         // add it to the list
  112.         gFileQueue.fFlistNumItems++;
  113.         if (gFileQueue.fFlist == NULL)
  114.         { // first on list
  115.             gFileQueue.fFlist = newFlistHdl;
  116.             gFileQueue.fFlistEnd = newFlistHdl;
  117.             // track head of list for Get routine
  118.             gFileQueue.fFlistGetter = gFileQueue.fFlist;
  119.         }
  120.         else
  121.         { // next on list
  122.             // connect new record onto end of list
  123.             (**gFileQueue.fFlistEnd).fNext = (Handle)newFlistHdl;
  124.             // point list's end to this new record
  125.             // (essentially, we appended the new record at end of list)
  126.             gFileQueue.fFlistEnd = newFlistHdl;
  127.         }
  128.     }
  129. } // FileQ_Put
  130.  
  131.  
  132.  
  133. // ------------------------------------------------------------------
  134. // Retrieve the next file from the list (increments after each call)
  135. Boolean FileQ_Get(FSSpecPtr    pFSSpecPtr)
  136. {
  137.     Boolean        GotIt = false;
  138.  
  139.     if (gFileQueue.fFlistGetter != NULL)
  140.     {
  141.         gFileQueue.fFlistNumItems--;
  142.         // get it
  143.         *pFSSpecPtr = (**gFileQueue.fFlistGetter).fFSSpec;
  144.         GotIt = true;
  145.         // move to next record
  146.         gFileQueue.fFlistGetter = (flisthdl_t)(**gFileQueue.fFlistGetter).fNext;
  147.         // if we fell off last item in list, destroy the list
  148.         if (gFileQueue.fFlistGetter == NULL)
  149.             FileQ_d();
  150. #if defined (DO_DEBUG)
  151. printf("GetFileFromList - '%P'\n",pFSSpecPtr->name);
  152. #endif // DO_DEBUG
  153.     }
  154.  
  155.     return GotIt;
  156.  
  157. } // FileQ_Get
  158.  
  159.  
  160. // ------------------------------------------------------------------
  161. // Return the # of items in the queue
  162. short FileQ_NumItems(void)
  163. {
  164.     return gFileQueue.fFlistNumItems;
  165. } // FileQ_NumItems
  166.  
  167.  
  168. // ------------------------------------------------------------------
  169. // Delete the list and its contents after its use
  170. void FileQ_d()
  171. {
  172.     flisthdl_t    anFlistHdl, nextFlistHdl;
  173.  
  174.     // start at head of list
  175.     anFlistHdl = gFileQueue.fFlist;
  176.  
  177.     // dispose of every record on the list
  178.     while (anFlistHdl != NULL)
  179.     {
  180. #if defined (DO_DEBUG)
  181. printf("FileQ_d - '%P'\n",(**anFlistHdl).fFSSpec.name);
  182. #endif // DO_DEBUG
  183.         // remember next in line
  184.         nextFlistHdl = (flisthdl_t)(**anFlistHdl).fNext;
  185.         // delete current
  186.         DisposeHandle((Handle)anFlistHdl);
  187.         // move to next in line
  188.         anFlistHdl = nextFlistHdl;
  189.     }
  190.  
  191.     // the coup de gras
  192.     FileQ_c();
  193.  
  194. } // FileQ_d
  195.  
  196.  
  197.